<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of HouseModel
 *
 * @author yaoyunhua
 */
namespace Admin\Model;
use Think\Model;

class ConfigModel  extends Model {
    //put your code here
    protected  $tableName = 'config';

    public function detail($where) {
        $row = $this->relation(true)->where($where)->find();
        return $row;
    }

    public function getList($where=array()) {
        $data = array();
        $dataList = $this->where($where)->select();
        $data['list'] = $dataList;
        return $data;
    }

    public function add($data) {
        $items = array();
        $type = $data['type'];
        $label = $data['label'];
        $unit = $data['unit'];
        unset($data['type']);
        unset($data['label']);
        unset($data['unit']);
        $index = 0;
        foreach ($data as $key => $value) {
            $items[] = array(
                'key' => $key,
                'value' => $value,
                'type' => $type,
                'label' => $label[$index],
                'unit' => $unit[$index]
            );
            $index++;
        }
        $rs = $this->remove(array('type' => $type));
        if ($rs !== false) {
            return parent::addAll($items);
        }
        return false;
    }

    public function update($data,$where) {
        $rs = $this->where($where)->save($data);
        return $rs;
    }

    public function remove($where) {
        $rs = $this->where($where)->delete();
        return $rs;
    }
}